﻿// Decompiled with JetBrains decompiler
// Type: Netick.Unity.QuaternionErrorCorrector
// Assembly: Netick.Unity, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E128C7FD-39ED-4452-86AC-6EC748457030
// Assembly location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.Unity.dll
// XML documentation location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.Unity.xml

using System;
using System.Runtime.CompilerServices;
using UnityEngine;

#nullable disable
namespace Netick.Unity;

/// <summary>
/// Handles prediction error correction smoothing for a Quaternion.
/// </summary>
[Serializable]
public struct QuaternionErrorCorrector
{
  public Quaternion QuaternionPreRollback;
  public Quaternion QuaternionError;

  public void Init(Quaternion value)
  {
    this.QuaternionPreRollback = value;
    this.QuaternionError = new Quaternion();
  }

  public void OnPreRollback(Quaternion value) => this.QuaternionPreRollback = value;

  public void OnPostResimulation(Quaternion currentValue)
  {
    this.QuaternionError = Quaternion.Inverse(currentValue) * this.QuaternionPreRollback * this.QuaternionError;
  }

  [MethodImpl(MethodImplOptions.AggressiveInlining)]
  public void Render(
    Quaternion interpolatedValue,
    float correctionMultiplier,
    float teleportThreshold,
    float deltaTime)
  {
    double num = (double) Mathf.Exp(-correctionMultiplier * deltaTime);
    this.QuaternionError = Quaternion.Slerp(this.QuaternionError, Quaternion.identity, correctionMultiplier * deltaTime);
    interpolatedValue *= this.QuaternionError;
  }
}
